package org.example.java.base;

import java.util.Calendar;

/**
 * %[argument_index$][flags][width][.precision]conversion
 * 其中：
 * argument_index是一个正整数，说明了参数的位置，1为取第一个参数
 * width表示输出的最小字母个数
 * precision代表数字的小数位数
 * conversion代表被格式化的参数的类型：
 * f  float,
 * t  time
 * d  decimal
 * o octal   八进制
 * x  hexadecimal  十六进制
 * s  general
 * c  a Unicode character
 */
public class FormatTest {
  public static void main(String[] args) {
    //%n==\n
    System.out.printf("hello\nworld%nzjt%n");
    System.out.printf("====%n");
    //format
    System.out.format("Pi is approximately %f, and e is about %f\n", Math.PI, Math.E);
    //printf
    System.out.printf("Pi is approximately %f, and e is about %f\n", Math.PI, Math.E);
    //保留2位小数点
    System.out.printf("Pi is approximately %.2f, and e is about %.2f\n", Math.PI, Math.E);
    //输出(有空格来填补长度)
    System.out.printf("Pi is approximately %6.2f, and e is about %6.2f\n", Math.PI, Math.E);

    System.out.printf("e is about %2$f," + "and pi is approximately %1$f\n", Math.PI, Math.E);

    /*
     tr  hour and minute,
     tA  the day of the week
     tB  the name of the month
     te  the number of the day of the month
     tY  the year
     */
    System.out.printf("Right now it is %tr on %<tA, %<tB %<te, %<tY.%n", Calendar.getInstance());
  }
}
